﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using System.Collections.ObjectModel;
using System.IO;
using produccion.vistamodelo;
using System.ComponentModel;
using produccion.clases;

namespace produccion.forms
{
    /// <summary>
    /// Lógica de interacción para FRMVerMaterial.xaml
    /// </summary>
    public partial class FRMVerMaterial : Window
    {
        vermaterial _vermaterial;

        public FRMVerMaterial()
        {
            InitializeComponent();
            _vermaterial = (vermaterial)this.DataContext;
        }

        private void butSal_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            ordenprodauto.Instance = null;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            
        }

        public void consultar()
        {
            try
            {
                _vermaterial.consultaMaterial(txtCodMat.Text.ToString().Trim());
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
    }

    public class vermaterial:ObservableObject
    {
        #region singleton

            private static vermaterial instance = null;

            //----------------------------------------------------------------------------
            protected vermaterial() 
            {

                MDOgeneral.conectar();
                strTituloVentana = "Ver Materiales - Usuario: " + MDOgeneral.usuario + " - [FRMVerMateriales]";
            }

            public static vermaterial Instance
            {
                get 
                {
                    if (instance == null)
                        instance = new vermaterial();
                    return instance;
                }
                set 
                { 
                    if (instance != null)
                        instance = null;
                }
            }

        #endregion

        #region propiedades nuevas
            
            private string _strTituloVentana;
            public string strTituloVentana
            {
                get { return _strTituloVentana; }
                set { _strTituloVentana = value; RaisePropertyChangedEvent("strTituloVentana"); }
            }

            private string _strCodigoMat;
            public string strCodigoMat
            {
                get { return _strCodigoMat; }
                set { _strCodigoMat = value; RaisePropertyChangedEvent("strCodigoMat"); }
            }

            private string _strNomMaterial;
            public string strNomMaterial
            {
                get { return _strNomMaterial; }
                set { _strNomMaterial = value; RaisePropertyChangedEvent("strNomMaterial"); }
            }

            private string _strCodigoCol;
            public string strCodigoCol
            {
                get { return _strCodigoCol; }
                set { _strCodigoCol = value; RaisePropertyChangedEvent("strCodigoCol"); }
            }

            private string _strNomColor;
            public string strNomColor
            {
                get { return _strNomColor; }
                set { _strNomColor = value; RaisePropertyChangedEvent("strNomColor"); }
            }

            private DataTable _dtConsulta;
            public DataTable dtConsulta
            {
                get { return _dtConsulta; }
                set { _dtConsulta = value; RaisePropertyChangedEvent("dtConsulta"); }
            }
            
        #endregion

        #region Metodos

            public void consultaMaterial(string strCodMat)
            {
                try
                {
                    MDOgeneral mod = new MDOgeneral();
                    string query = "select b.codprv_prv, b.nomprv_prv, a.costo_pxm from prvmat a inner join maeprvp b on a.codprv_pxm = b.codprv_prv where a.codmat_pxm = '" + strCodMat + "'";
                    dtConsulta = mod.consulta(query);
                }
                catch (Exception ex) { throw ex; }
            }
            
            
        #endregion
    }

}
